package com.ruoyi.member.service.impl;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.db.mapper.MemberExtInfoMapper;
import com.ruoyi.market.utils.SysNumberUtil;
import com.ruoyi.member.service.IMemberExtInfoIndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 用户扩展信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-08-02
 */
@Service
@DataSource(DataSourceType.SLAVE)
public class MemberExtInfoIndexServiceImpl implements IMemberExtInfoIndexService
{
    @Autowired
    private MemberExtInfoMapper memberExtInfoMapper;

    @Override
    public List<Map<String, Object>> getDataSortZhimaInfo(Integer type) {

        LocalDate localDate = LocalDate.now();

        if (type == 1){
            // 昨天
            localDate = localDate.minusDays(1);
        }else if (type == 2){
            // 近三天
            localDate = localDate.minusDays(2);
        }else if (type == 3){
            // 近五天
            localDate = localDate.minusDays(4);
        }
        // 根据条件查询 全国的数据

        String dateInfo = localDate.toString();
        Long number = memberExtInfoMapper.countAuthNumber(localDate.toString());

        Integer zhima700Num = memberExtInfoMapper.getDataSortZhimaInfo(dateInfo, "zm005");
        Integer zhima650Num = memberExtInfoMapper.getDataSortZhimaInfo(dateInfo, "zm004");
        Integer zhima600Num = memberExtInfoMapper.getDataSortZhimaInfo(dateInfo, "zm003");
        Integer zhima001Num = memberExtInfoMapper.getDataSortZhimaInfo(dateInfo, "zm002");
        Integer zhima000Num = memberExtInfoMapper.getDataSortZhimaInfo(dateInfo, "zm001");

        Map<String, Object> zhima700Map = new HashMap<>();
        zhima700Map.put("name","芝麻700以上");
        zhima700Map.put("number", zhima700Num);
        zhima700Map.put("rate", String.valueOf(SysNumberUtil.getPointNumber(new BigDecimal(zhima700Num), new BigDecimal(number), 4)));

        Map<String, Object> zhima650Map = new HashMap<>();
        zhima650Map.put("name","芝麻650-700");
        zhima650Map.put("number", zhima650Num);
        zhima650Map.put("rate", String.valueOf(SysNumberUtil.getPointNumber(new BigDecimal(zhima650Num), new BigDecimal(number), 4)));

        Map<String, Object> zhima600Map = new HashMap<>();
        zhima600Map.put("name","芝麻600-650");
        zhima600Map.put("number",zhima600Num);
        zhima600Map.put("rate", String.valueOf(SysNumberUtil.getPointNumber(new BigDecimal(zhima600Num), new BigDecimal(number), 4)));

        Map<String, Object> zhima001Map = new HashMap<>();
        zhima001Map.put("name","芝麻1-600");
        zhima001Map.put("number",zhima001Num);
        zhima001Map.put("rate", String.valueOf(SysNumberUtil.getPointNumber(new BigDecimal(zhima001Num), new BigDecimal(number), 4)));

        Map<String, Object> zhima000Map = new HashMap<>();
        zhima000Map.put("name","无芝麻");
        zhima000Map.put("number",zhima000Num);
        zhima000Map.put("rate", String.valueOf(SysNumberUtil.getPointNumber(new BigDecimal(zhima000Num), new BigDecimal(number), 4)));

        List<Map<String, Object>> resultList = new ArrayList<>();
        Map<String, Object> totalMap = new HashMap<>();
        totalMap.put("name", "全国");
        totalMap.put("number", number);
        totalMap.put("rate", 100);
        resultList.add(totalMap);

        resultList.add(zhima700Map);
        resultList.add(zhima650Map);
        resultList.add(zhima600Map);
        resultList.add(zhima001Map);
        resultList.add(zhima000Map);

        return resultList;
    }

}
